package Kuang;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * description:下载图片
 * author:zcx
 * lenovo
 * 时间：2022.02.08.19.06
 */
public class Demo2 implements Runnable {

    private String url;//网络图片地址
    private String name;//保存的文件名
    public Demo2(String url,String name){
        this.url=url;
        this.name=name;
    }
    @Override
    public void run() {
        WebDownloader wl= new WebDownloader();
        wl.downloader(url,name);
        System.out.println("下载文件名为："+name);

    }

    //下载器
    static class WebDownloader {
        //下载方法
        public void downloader(String url,String name){
            try {
                FileUtils.copyURLToFile(new URL(url),new File(name));
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("IO异常，downloader方法出现问题");
            }
        }
    }

    public static void main(String[] args) {
        Demo2 t1=new Demo2("https://tenfei01.cfp.cn/creative/vcg/800/new/VCG211363439413.jpg","1.jpg");
        new Thread(t1).start();
    }
}
